<html>
<head>
	<link type="text/css" rel="stylesheet" href="../css/default.css" />
    <link type="text/css" rel="stylesheet" href="../js/rainbow/themes/sunburst.css">
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
</head>
<body>
	<div class="page">
<h2>IgeEventingClass <span>CLASS</span></h2>
<p>Declared in <a href="../../engine/core/IgeEventingClass.js">IgeEventingClass.js</a></p>
<div class="itemBox">
	<div class="header">Description</div>
	<div class="content">Creates a new class with the capability to emit events.</div>
</div>
<!--=if{extends}[-->
<div class="itemBox">
	<div class="header">Extends</div>
	<div class="content"><a href="IgeClass.html">IgeClass</a></div>
</div>
<!--=if{extends}]-->
<h2>Methods</h2><a name="on"></a>
<h3 class="methodTitle">on</h3>
<div class="methodSection">
    <!--=if{desc}[-->
    <div class="methodDesc">Add an event listener method for an event.</div>
    <!--=if{desc}]-->
    <div class="methodDefinition"><span class="methodName">on</span>({<span class="argType">String || Array</span>} <span class="argName">eventName</span>, {<span class="argType">Function</span>} <span class="argName">call</span>, {<span class="argType">Object</span>} <span class="argName">context</span>, {<span class="argType">Boolean</span>} <span class="argName">oneShot</span>, {<span class="argType">Boolean</span>} <span class="argName">sendEventName</span>)</div>
    <div class="methodArgs"><ul class="argList"><li>{<span class="argType">String || Array</span>}<span class="argName">eventName</span> The name of the event to listen for (string), or an array of events to listen for.</li><li>{<span class="argType">Function</span>}<span class="argName">call</span> The method to call when the event listener is triggered.</li><li>{<span class="argType">Object</span>}<span class="argName">context</span> The context in which the call to the listening method will be made (sets the 'this' variable in the method to the object passed as this parameter).</li><li>{<span class="argType">Boolean</span>}<span class="argName">oneShot</span> If set, will instruct the listener to only listen to the event being fired once and will not fire again.</li><li>{<span class="argType">Boolean</span>}<span class="argName">sendEventName</span> If set, will instruct the emitter to send the event name as the argument instead of any emitted arguments.</li></ul></div>
    <div class="methodReturnDesc">Returns {<span class="argType">Object</span>} The event listener object. Hold this value if you later want to turn off the event listener.</div>
    
					<div class="methodExample">
						<div class="content"><h1>Add an Event Listener</h1>

<pre><code>// Register event lister and store in "evt"
var evt = myEntity.on('mouseDown', function () { console.log('down'); });
</code></pre>
</div>
					</div>
				
					<div class="methodExample">
						<div class="content"><h1>Listen for Event Data</h1>

<pre><code>// Set a listener to listen for the data (multiple values emitted
// from an event are passed as function arguments)
myEntity.on('hello', function (arg1, arg2) {
    console.log(arg1, arg2);
}

// Emit the event named "hello"
myEntity.emit('hello', ['data1', 'data2']);

// The console output is:
//  data1, data2
</code></pre>
</div>
					</div>
				
</div><a name="off"></a>
<h3 class="methodTitle">off</h3>
<div class="methodSection">
    <!--=if{desc}[-->
    <div class="methodDesc">Remove an event listener. If the _processing flag is true then the removal will be placed in the removals array to be processed after the event loop has completed in the emit() method.</div>
    <!--=if{desc}]-->
    <div class="methodDefinition"><span class="methodName">off</span>({<span class="argType">Boolean</span>} <span class="argName">eventName</span>, {<span class="argType">Object</span>} <span class="argName">evtListener</span>)</div>
    <div class="methodArgs"><ul class="argList"><li>{<span class="argType">Boolean</span>}<span class="argName">eventName</span> The name of the event you originally registered to listen for.</li><li>{<span class="argType">Object</span>}<span class="argName">evtListener</span> The event listener object to cancel. This object is the one returned when calling the on() method. It is NOT the method you passed as the second argument to the on() method.</li></ul></div>
    <div class="methodReturnDesc">Returns {<span class="argType">Boolean</span>} </div>
    
					<div class="methodExample">
						<div class="content"><h1>Switch off an Event Listener</h1>

<pre><code>// Register event lister and store in "evt"
var evt = myEntity.on('mouseDown', function () { console.log('down'); });

// Switch off event listener
myEntity.off('mouseDown', evt);
</code></pre>
</div>
					</div>
				
</div><a name="emit"></a>
<h3 class="methodTitle">emit</h3>
<div class="methodSection">
    <!--=if{desc}[-->
    <div class="methodDesc">Emit an event by name.</div>
    <!--=if{desc}]-->
    <div class="methodDefinition"><span class="methodName">emit</span>({<span class="argType">Object</span>} <span class="argName">eventName</span>, {<span class="argType">Object || Array</span>} <span class="argName">args</span>)</div>
    <div class="methodArgs"><ul class="argList"><li>{<span class="argType">Object</span>}<span class="argName">eventName</span> The name of the event to emit.</li><li>{<span class="argType">Object || Array</span>}<span class="argName">args</span> The arguments to send to any listening methods. If you are sending multiple arguments, use an array containing each argument.</li></ul></div>
    <div class="methodReturnDesc">Returns {<span class="argType">Number</span>} </div>
    
					<div class="methodExample">
						<div class="content"><h1>Emit an Event</h1>

<pre><code>// Emit the event named "hello"
myEntity.emit('hello');
</code></pre>
</div>
					</div>
				
					<div class="methodExample">
						<div class="content"><h1>Emit an Event With Data Object</h1>

<pre><code>// Emit the event named "hello"
myEntity.emit('hello', {moo: true});
</code></pre>
</div>
					</div>
				
					<div class="methodExample">
						<div class="content"><h1>Emit an Event With Multiple Data Values</h1>

<pre><code>// Emit the event named "hello"
myEntity.emit('hello', [{moo: true}, 'someString']);
</code></pre>
</div>
					</div>
				
					<div class="methodExample">
						<div class="content"><h1>Listen for Event Data</h1>

<pre><code>// Set a listener to listen for the data (multiple values emitted
// from an event are passed as function arguments)
myEntity.on('hello', function (arg1, arg2) {
    console.log(arg1, arg2);
}

// Emit the event named "hello"
myEntity.emit('hello', ['data1', 'data2']);

// The console output is:
//  data1, data2
</code></pre>
</div>
					</div>
				
</div><a name="eventList"></a>
<h3 class="methodTitle">eventList</h3>
<div class="methodSection">
    <!--=if{desc}[-->
    <div class="methodDesc">Returns an object containing the current event listeners.</div>
    <!--=if{desc}]-->
    <div class="methodDefinition"><span class="methodName">eventList</span>()</div>
    <div class="methodArgs"></div>
    <div class="methodReturnDesc">Returns {<span class="argType">Object</span>} </div>
    
</div><a name="_processRemovals"></a>
<h3 class="methodTitle">_processRemovals</h3>
<div class="methodSection">
    <!--=if{desc}[-->
    <div class="methodDesc">Loops the removals array and processes off() calls for each array item.</div>
    <!--=if{desc}]-->
    <div class="methodDefinition"><span class="methodName">_processRemovals</span>()</div>
    <div class="methodArgs"></div>
    <div class="methodReturnDesc"></div>
    
</div>	</div>
    <script type="text/javascript">
        $(function () {
            $('code').attr('data-language', 'javascript');
        });
    </script>
    <script type="text/javascript" src="../js/rainbow/rainbow-custom.min.js"></script>
</body>
</html>